package com.atomikos.controller;

import com.atomikos.entity.UserEntity;
import com.atomikos.service.AddUserOneService;
import com.atomikos.service.AddUserTwoService;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {


    @Autowired
    AddUserOneService oneService;

    @Autowired
    AddUserTwoService twoService;


    @GetMapping("/testTrans")
    @Transactional
    public String testTrans() {
        UserEntity userEntity = new UserEntity();
        userEntity.setId("1");
        userEntity.setUserName("test1");
        userEntity.setLoginName("test1");
        userEntity.setPasswd("test1");
        oneService.saveOne(userEntity);

        UserEntity userBakEntity = new UserEntity();
        userBakEntity.setId("2");
        userBakEntity.setUserName("test2");
        userBakEntity.setLoginName("test2");
        userBakEntity.setPasswd("test2");
        twoService.saveTwo(userBakEntity);
        //int i =1/0;
        return "OK";
    }

    @GetMapping("/query")
    public String query(){
        List<UserEntity> query = oneService.queryList();
        List<UserEntity> userEntities = twoService.queryList();
        System.out.println(query.toString()+","+userEntities.toString());
        return query.toString()+","+userEntities.toString();
    }
}
